///************************************************************************
/// <copyrigth>2018-2019 Corporation.All Rights Reserved</copyrigth>
/// <author>tangyingzhong</author>
/// <contact>tangyz114987@outlook.com</contact>
/// <version>v1.0.0</version>
/// <describe>
/// It is framework of the whole system
///</describe>
/// <date>2020/7/26</date>
///***********************************************************************
#ifndef FRAMEWORK_H
#define FRAMEWORK_H

#include <mutex>
#include "IMicroCore.h"
#include "Model/IFramework.h"

class Framework:public PluginBase<IFramework>
{
public:
	// Get instance
	static Framework* GetInstance();

	// Destory the instance
	static void DestoryInstance();

private:
	// Construct the Framework
	Framework();

	// Detructe the Framework
	~Framework();

	// Forbid the copy Framework
	Framework(const Framework& other){	};
	
	// Forbid the assigment of Framework
	Framework& operator=(const Framework& other) { return *this; };
	
public:
	// Start the framework
	virtual bool Start();

	// Stop the framework
	virtual bool Stop();

	// Is core's debug mode
	virtual bool IsDebugMode();

	// Get the plugin by name and version
	virtual IPlugin* GetPlugin(std::string strPluginName,
		int iMajorVersion,
		int iMinorVersion,
		int iModifyVersion);

	// Add Task to the micro core
	virtual bool AddTask(Task& UserTask);

	// Pause the task
	virtual void PauseTask(std::string strTaskId);

	// Resume the task
	virtual void ResumeTask(std::string strTaskId);

	// Stop the task
	virtual void StopTask(std::string strTaskId);

private:
	// Start micro core
	bool StartMicroCore();

	// Stop the micro core
	bool StopMicroCore();

private:
	// Initialize the Framework
	void Initialize();
	
	// Destory the Framework
	void Destory();

	// Create micro core
	void CreateMicroCore();

	// Destory micro core
	void DestoryMicroCore();

private:
	// Get micro core
	inline IMicroCore* GetMicroCore() const
	{
		return m_pCore;
	}

	// Set micro core
	inline void SetMicroCore(IMicroCore* pCore)
	{
		m_pCore = pCore;
	}

	// Get the disposed status
	inline bool GetDisposed() const
	{
		return m_bDisposed;
	}
	
	// Set the disposed status
	inline void SetDisposed(bool bDisposed)
	{
		m_bDisposed = bDisposed;
	}

private:
	// Instance itself
	static Framework* m_pInstance;

	// Instance lock
	static std::mutex* m_InstanceLock;

private:
	// Micro core
	IMicroCore* m_pCore;

	// Micro core loader
	PluginLoader<IMicroCore> m_CoreLoader;

	// Disposed status
	bool m_bDisposed;	
};
	
#endif // FRAMEWORK_H
